package com.person.jc.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.person.jc.common.Constants;
import com.person.jc.entity.TsUser;
import org.apache.commons.lang.StringUtils;

public class LoginInterceptor implements Interceptor {

	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		TsUser tsUser = (TsUser)controller.getSessionAttr(Constants.LOGIN_USER);
		if(tsUser == null){

			String url=controller.getRequest().getRequestURI();
			if(url.endsWith("/makeController/showCertificateList")
					|| url.endsWith("/template/showCertFront")
					|| url.endsWith("/jc/template/showCertBack")
					|| url.endsWith("/template/viewOriginalRecord")){
//				String str=controller.getCookie(Constants.LOGIN_USER);
//				if(StringUtils.isNotEmpty(str)){
					inv.invoke();
//				}
			}else{

				controller.redirect("/login");
			}


		}else{
			inv.invoke();
		}
		      
	}

}
